AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

util.PrecacheSound("ambient/levels/labs/electric_explosion1.wav")


function ENT:Initialize()
	self.Entity:SetModel( "models/items/AR2_Grenade.mdl" )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetKeyValue("rendermode", "10")
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:SetAngles(self.Entity:GetAngles())
	local light = ents.Create("env_lightglow") //Nice little glow from the rocket flame
	light:SetPos(self.Entity:GetPos())
	light:SetKeyValue("targetname", "moo")
	local lightcache = math.random(50,255) .. " " ..math.random(50,255) .. " " ..math.random(50,255)
	light:SetKeyValue("rendercolor", tostring(lightcache))
	light:SetKeyValue("VerticalGlowSize", "10")
	light:SetKeyValue("HorizontalGlowSize", "10")
	light:Spawn()
	light:SetParent(self.Entity)
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then	
		phys:Wake()
		phys:EnableGravity(false)
		phys:EnableDrag(false)
	end
end

function ENT:PhysicsCollide()
	util.BlastDamage(self.Entity, self.Entity, self.Entity:GetPos(), 30, 500)
	util.ScreenShake( self.Entity:GetPos(), 100, 5, 1, 300 )
	local pos = self.Entity:GetPos()
	local effectdata = EffectData() 
	effectdata:SetStart( pos) 
	effectdata:SetOrigin( pos ) 
	effectdata:SetScale( 200 ) 
	effectdata:SetMagnitude(39)
	effectdata:SetEntity(self.Entity)
	util.Effect( "hit", effectdata,true,true ) 
	self.Entity:EmitSound("ambient/levels/labs/electric_explosion1.wav")
	self:Fire("kill",0,0) 
end


function ENT:Think()
	local pos1 = self.target:GetPos()
	local pos2 = self.Entity:GetPos()
	local vector = pos1 - pos2
	self.Entity:SetAngles(vector:Normalize():Angle())
	self.Entity:NextThink( CurTime() + 0.5 )
	return true
end
